#pragma once
#include <vector>

namespace lxy
{
  //N个比特位
  template<size_t N>
  class bitset
  {

  public:
    bitset()
    {
      _bits.resize(N/8 + 1,0);
    }

    //x映射的位标记成1
    void set(size_t x)
    {
      size_t i = x/8;
      size_t j = x % 8;
      _bits[i] |= (1<<j);
    }

    void reset(size_t x)
    {
      size_t i  = x/8;
      size_t j  = x % 8;

      _bits[i] &= (~(1<<j));
    }

    bool test(size_t x )
    {
      size_t  i = x/8;
      size_t j = x % 8;
      return _bits[i] & (1<<j);
    }
  
  private:
    std::vector<int> _bits;

  };

  void test_bit_set1()
  {
    bitset<100> bs;
    bs.set(18);
    bs.set(19);

    cout<<bs.test(18)<<endl;
    cout<<bs.test(19)<<endl;
    cout<<bs.test(20)<<endl;

    bs.reset(18);
    bs.reset(18);

    cout<<bs.test(18)<<endl;                                                                       
    cout<<bs.test(19)<<endl;                                                                       
    cout<<bs.test(20)<<endl;
  }
}
